package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.OrderHistory;
import com.ruoyi.system.domain.SysUserRole;
import com.ruoyi.system.mapper.OrderHistoryMapper;
import com.ruoyi.system.mapper.SysUserRoleMapper;
import com.ruoyi.system.service.IOrderHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 订单历史Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-06-25
 */
@Service
public class OrderHistoryServiceImpl implements IOrderHistoryService
{
    @Autowired
    private OrderHistoryMapper orderHistoryMapper;
    @Autowired
    private SysUserRoleMapper sysUserRoleMapper;

    /**
     * 查询订单历史
     * 
     * @param orderHistoryId 订单历史主键
     * @return 订单历史
     */
    @Override
    public OrderHistory selectOrderHistoryByOrderHistoryId(Long orderHistoryId)
    {
        return orderHistoryMapper.selectOrderHistoryByOrderHistoryId(orderHistoryId);
    }

    /**
     * 查询订单历史列表
     * 
     * @param orderHistory 订单历史
     * @return 订单历史
     */
    @Override
    public List<OrderHistory> selectOrderHistoryList(OrderHistory orderHistory)
    {
        Long userId= SecurityUtils.getUserId();
        SysUserRole sysUserRole= sysUserRoleMapper.getUserRole(userId);
        if(sysUserRole.getRoleId()==101){
            orderHistory.setUserId(userId);
        }
        return orderHistoryMapper.selectOrderHistoryList(orderHistory);
    }

    /**
     * 新增订单历史
     * 
     * @param orderHistory 订单历史
     * @return 结果
     */
    @Override
    public int insertOrderHistory(OrderHistory orderHistory)
    {
        return orderHistoryMapper.insertOrderHistory(orderHistory);
    }

    /**
     * 修改订单历史
     * 
     * @param orderHistory 订单历史
     * @return 结果
     */
    @Override
    public int updateOrderHistory(OrderHistory orderHistory)
    {
        return orderHistoryMapper.updateOrderHistory(orderHistory);
    }

    /**
     * 批量删除订单历史
     * 
     * @param orderHistoryIds 需要删除的订单历史主键
     * @return 结果
     */
    @Override
    public int deleteOrderHistoryByOrderHistoryIds(Long[] orderHistoryIds)
    {
        return orderHistoryMapper.deleteOrderHistoryByOrderHistoryIds(orderHistoryIds);
    }

    /**
     * 删除订单历史信息
     * 
     * @param orderHistoryId 订单历史主键
     * @return 结果
     */
    @Override
    public int deleteOrderHistoryByOrderHistoryId(Long orderHistoryId)
    {
        return orderHistoryMapper.deleteOrderHistoryByOrderHistoryId(orderHistoryId);
    }
}
